
package com.example.mobile2121606109ycg0407;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivityTip8 extends AppCompatActivity {
    private EditText edtTxtMain8Num;
    private TextView tvMain8Result;
    private Button btnMain8Result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tip8);
        initView();

        btnMain8Result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取输入的利润
                double profit = Double.parseDouble(edtTxtMain8Num.getText().toString());
                //计算奖金并输出结果
                double bonus = 0;
                if (profit <= 100000){
                    bonus =  profit * 0.1;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }else if (profit>100000 && profit<=200000){
                    bonus = ((profit-100000)*0.075)+10000;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }else if (profit>200000 && profit<=400000){
                    bonus = ((profit-200000)*0.05)+10000+7500;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }else if (profit>400000 && profit<=600000){
                    bonus = ((profit-400000)*0.03)+10000+7500+5000;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }else if (profit>600000 && profit<=1000000){
                    bonus = ((profit-600000)*0.015)+10000+7500+5000+3000;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }else if (profit>1000000){
                    bonus = ((profit-1000000)*0.01)+10000+7500+5000+3000+1500;
                    tvMain8Result.setText(String.format("%.2f", bonus));
                }
            }
        });
    }

    private void initView() {
        edtTxtMain8Num = (EditText) findViewById(R.id.edtTxtMain8_Num);
        tvMain8Result = (TextView) findViewById(R.id.tvMain8_Result);
        btnMain8Result = (Button) findViewById(R.id.btnMain8_Result);
    }
}